package util;

import model.GameRecord;
import model.GameType;
import org.apache.log4j.Logger;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author Alex Vikharev vikharev@yandex-team.ru
 *         created 23.02.12
 */
public class GameLoader {
    private static final Logger log = Logger.getLogger(GameLoader.class);

    public static List<GameRecord> load(String fileName, GameType gameType) throws IOException{
        InputStream input = new FileInputStream(fileName);
        byte[] b = new byte[16];
        List<GameRecord> result = new ArrayList<>();
        while (input.read(b, 0, 16) != -1) {
            log.debug("Load " + Arrays.toString(b));
            result.add(GameRecord.fromBytes(b, gameType));
        }
        input.close();
        return result;
    }
}
